<?php
if (!defined("BASEPATH")) exit("No direct script access allowed");

class Currency extends MY_Model {

	function __construct() {
		parent::__construct();
		$this->tableName = "currency";
		$this->prefix = "curr";
	}

	function getCurrency($where = NULL, $start = NULL, $limit = NULL, $fields = NULL, $query = NULL, $order = "currOrder", $dir = "ASC") {

		$fieldsQuery = Common::fieldsquery($fields, $query);
		$order = Common::coalesce(array($order, "currOrder"));
		$dir = Common::coalesce(array($dir, "ASC"));

		$qs =	"
					select
						curr_id, curr_text, curr_order
					from
						".$this->db->dbprefix.$this->tableName."
					where
						curr_del = 0 ".((!is_null($where))?(" and ".$where):(""))." ".(($fieldsQuery)?(" and (".$fieldsQuery.") "):(""))."
					order by
						".(($order == "rand()")?($order):(Common::underscore($order)." ".$dir))."
					".((is_numeric($start))?(" limit ".$start.",".$limit):(""))."
						";
						//Common::pr($qs);
		$result = $this->db->query($qs);

		$getCurrency = array();
		if($result->num_rows()) {
			foreach ($result->result() as $row) {
				$getCurrency[] = array(
					"currId" => $row->curr_id,
					"currText" => $row->curr_text,
					"currOrder" => $row->curr_order,
				);
			}

		}

		return $getCurrency;
	}

}